import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';

import '../model/order_request_data.dart';
import '../model/week_food_model.dart';

class RequestDayMenuViewModel extends BaseViewModel{
  final OrderRequestData orderData;
  String orderDate;
  var weekMenuModel = WeekFoodModel();
  Map<String, dynamic>? menuData;

  RequestDayMenuViewModel(BuildContext? context,{required this.orderData,required this.orderDate}) : super(context);

  @override
  void onCreated() {
    super.onCreated();
    getWeekMenu();
  }

  Future<void> getWeekMenu() async {
    showLoadingState();
    try {
      menuData = await weekMenuModel.getWeekMenuByDay(
          siteId: orderData.siteId,
          date: orderDate,
          elderHumanId: orderData.elderHumanId,
          timeSection: orderData.timeSection);
      orderData.menuId = menuData!["menuId"];
      var menuList = menuData!['menuList'] as List;
      if (menuList.isEmpty) {
        showEmptyState(msg: "无菜单数据");
      } else {
        showContent();
        notifyListeners();
      }
    } catch (e) {
      showErrorState( e.toNetError());
    }
  }


}